<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=0,maximum-scale=1.0"/>
    <script src="http://g.tbcdn.cn/mtb/lib-flexible/0.3.4/??flexible_css.js,flexible.js"></script>
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/css/reset.css"/>
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/css/style.css"/>
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="__PUBLIC__/js/public.js" type="text/javascript" charset="utf-8"></script>
    <title>领优惠券</title>
</head>
<body>
<div id="receive">
    <div class="showCoupon">
        <foreach name="list" item="v" key="k">
            <div class="couponList">
                <img class="bg" src="__PUBLIC__/images/bg_youhuijuan@2x.png"/>
                <div class="listCon">
                    <div class="priceCon">
                        <span class="listPrice">￥<i class="price">{$v['money']}</i>店铺优惠券</span>
                        <span class="use">满<span class="num">{$v['condition_money']}</span>元使用</span>
                    </div>
                    <div class="listTime"><i class="icon"></i>有效期<span class="term">{$v['use_start_time']|date="Y.m.d",###}-{$v['use_end_time']|date="m.d",###}</span>
                    </div>
                    <span id="getCoupon" onclick="getCoupon(this,{$v['coupon_id']})" class="receive">{$v['status']}</span>
                </div>
            </div>
        </foreach>
    </div>
    <a href="javascript:history.back(-1)" class="complete">完成</a>
    <div class="noneCoupon">
        <img class="icon" src="__PUBLIC__/images/image1@2x.png"/>
        <span class="name">没有优惠券</span>
    </div>

</div>
<script type="text/javascript">
    $(document).ready(function () {
        var list = $('.showCoupon').children().length
        if (list <= 0) {
            $('.noneCoupon').show()
            $('.complete').hide()
            $('.showCoupon').hide()
        } else {
            $('.noneCoupon').hide()
            $('.complete').show()
            $('.showCoupon').show()
        }
    });

    //点击领取优惠券
    function getCoupon(this1,coupon_id) {
        if(coupon_id){
            $.ajax({
                url:"{:U('Home/Coupon/ajax_getCoupon')}",
                dataType: "JSON",
                async: true,
                type: "GET",
                data:{
                    coupon_id:coupon_id
                },
                success: function (data) {
                    //请求成功时处理
                    if(data.state==1){
                    alert('领取成功')
                       $(this1).text('已领取');
                    }else if(data.state==0){
                        alert('请求失败请重试')
                    }else if(data.state==-1){
                        alert('缺少参数请检查')
                    }else if(data.state==-2){
                        alert('已经领取过了')
                    }
                }
            })
        }
    }
</script>
</body>
</html>

